package com.chujian.framework.ws.support.send;

import cn.hutool.core.util.IdUtil;
import com.chujian.framework.ws.WsMsg;
import com.chujian.framework.ws.IWsSendMsgWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.PriorityOrdered;

/**
 * 消息发送器，填充一些调用者没有赋值的参数
 */
public class FillInfosMsgWrapper implements IWsSendMsgWrapper, PriorityOrdered {

    @Override
    public WsMsg wrapper(WsMsg msg) {
        if (StringUtils.isEmpty(msg.getReqId())) {
            msg.setReqId(IdUtil.fastUUID());
        }
        if (null == msg.getCreTime()) {
            msg.setCreTime(System.currentTimeMillis());
        }
        return msg;
    }

    @Override
    public int getOrder() {
        return MsgWrapperOrder.FILL_INFOS_ORDER;
    }
}
